package com.gh.manager.team.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.gh.common.core.domain.entity.SysUser;
import com.gh.common.core.redis.RedisCache;
import com.gh.common.utils.SecurityUtils;
import com.gh.manager.team.domain.GhUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gh.common.annotation.Log;
import com.gh.common.core.controller.BaseController;
import com.gh.common.core.domain.AjaxResult;
import com.gh.common.enums.BusinessType;
import com.gh.manager.team.service.IGhUserService;
import com.gh.common.utils.poi.ExcelUtil;
import com.gh.common.core.page.TableDataInfo;

/**
 * 我的队友Controller
 *
 * @author andas
 * @date 2024-11-01
 */
@Slf4j
@RestController
@RequestMapping("/manager/team")
public class GhUserController extends BaseController
{
    @Autowired
    private IGhUserService ghUserService;

    /**
     * 查询我的队友列表
     */
    @PreAuthorize("@ss.hasPermi('manager:team:list')")
    @GetMapping("/mylist")
    public TableDataInfo list(GhUser ghUser)
    {
//        SysUser user = SecurityUtils.getLoginUser().getUser();
//        ghUser.setGrade(user.getGrade());
        startPage();
        List<GhUser> list = ghUserService.selectGhUserList(ghUser);
        return getDataTable(list);
    }



    /**
     * 导出我的队友列表
     */
    @PreAuthorize("@ss.hasPermi('manager:team:export')")
    @Log(title = "我的队友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GhUser ghUser)
    {
        List<GhUser> list = ghUserService.selectGhUserList(ghUser);
        ExcelUtil<GhUser> util = new ExcelUtil<GhUser>(GhUser.class);
        util.exportExcel(response, list, "我的队友数据");
    }

    /**
     * 获取我的队友详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:team:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(ghUserService.selectGhUserByUserId(userId));
    }

    /**
     * 新增我的队友
     */
    @PreAuthorize("@ss.hasPermi('manager:team:add')")
    @Log(title = "我的队友", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GhUser ghUser)
    {
        return toAjax(ghUserService.insertGhUser(ghUser));
    }

    /**
     * 修改我的队友
     */
    @PreAuthorize("@ss.hasPermi('manager:team:edit')")
    @Log(title = "我的队友", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GhUser ghUser)
    {
        return toAjax(ghUserService.updateGhUser(ghUser));
    }

    /**
     * 删除我的队友
     */
    @PreAuthorize("@ss.hasPermi('manager:team:remove')")
    @Log(title = "我的队友", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(ghUserService.deleteGhUserByUserIds(userIds));
    }
}
